/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.filesystem;

import java.io.File;

/**
 *
 * @author triki
 */

public class SharedFolder {

    private String path;
    private String[] fileList;
    private String extension;
    private int n;

    public SharedFolder(String path)
    {
        this.path = path;
        File f = new File(path);
        fileList = f.list();
        n = (int) f.length();
    }

    public String getPath()
    {
        return path;
    }

    public void loadFiles()
    {
        fileList = new File(path).list();
    }

    public void setFilter(String ext)
    {
        extension = new String(ext);
    }

    public void listFiles()
    {
        String aux = null;
        FileIterator fiter = new FileIterator(fileList);

        while(fiter.hasNext())
        {
            System.out.println(""+fiter.current());
            fiter.next();
        }
    }

    public boolean searchFile(String filename)
    {
        String aux = null;
        FileIterator fiter = new FileIterator(fileList);

        while(fiter.hasNext())
        {
            aux = fiter.current();
            if(aux.regionMatches(false, 0, filename, 0, filename.length()))
                return true;
            fiter.next();
        }
        return false;
    }

    public FileIterator getIterator()
    {
        return new FileIterator(fileList);
    }
}
